package com.share.PACManager;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.EditText;

public class SelectEditText extends EditText {

	public SelectEditText(Context context) {
		super(context);
		initView(context);
	}
	
	public SelectEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}
	
	private void initView(Context context)
	{
		showArrow(true);
	}
	
	private boolean showArrow;	
	public void showArrow(boolean show)
	{
		showArrow = show;
		invalidate();
	}
	
	@Override
	protected void onDraw(Canvas canvas)
	{
		if(!showArrow)
		{
			super.onDraw(canvas);
			return;
		}
		
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setColor(Color.GRAY);
		Path path = new Path();
		
		int x = getWidth() - 24;
		int y = getHeight() / 2;
		int r = 10;		
		
		if(isSelected())
		{
			path.moveTo(x - r, y+r/2);
			path.lineTo(x + r, y+r/2);
			path.lineTo(x, y-r);
		}
		else
		{
			path.moveTo(x, y+r);
			path.lineTo(x - r, y-r/2);
			path.lineTo(x + r, y-r/2);			
		}
		
		path.close();		
		canvas.drawPath(path, paint);		
		super.onDraw(canvas);
	}
}
